package com.example.recyclelibrary;

import android.animation.Animator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

import java.util.List;

/**
 * Created by Eddy on 5/5/17.
 * 自定义laoding的基类
 */

public abstract class BaseProgressController {
    private View mTarget;

    private List<Animator> mAnimators;

    public void setmTarget(View target){this.mTarget=target;}

    public View getTarget(){return mTarget;}

    public int getWidth(){return  mTarget.getWidth();}

    public int getHeigth(){return  mTarget.getHeight();}

    public void postInvalidate(){mTarget.postInvalidate();}

    public abstract void draw(Canvas canvas, Paint paint);

    public abstract List<Animator> createAnimation();

    public void initAnimation(){mAnimators=createAnimation();}

    public void setmAnimationStatus(AnimStatus animStatus){
        if(mAnimators==null)return;
        int count=mAnimators.size();
        for (int i=0;i<count;i++){
            Animator animator=mAnimators.get(i);
            boolean isRunning=animator.isRunning();
            switch (animStatus){
                case START:
                    if(!isRunning){
                        animator.start();
                    }
                    break;
                case END:
                    if(isRunning){
                        animator.end();
                    }
                    break;
                case CANCLE:
                    if(isRunning){
                        animator.cancel();
                    }
                    break;
            }
        }
    }

    public enum AnimStatus{
        START,END,CANCLE
    }
}
